var serverData = {};
serverData.key ='';
var	serverTable;

var serverData2 = {};
var	serverTable2;
//查看审批
jQuery('.submitBtn').on("click",function(){
	var selects = getSelect("#dataTable", 1);
	if (selects.length > 1) {
		$.springLemonDialog({
			content : "一次只能查看一条记录",// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				$(this).closeDialog(modal);
			}
		});
		return;
	}
	if (selects.length < 1) {
		$.springLemonDialog({
			content : "请选择要查看审批的记录",// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				$(this).closeDialog(modal);
			}
		});
		return;
	}
	var url;
	if(selects[0].processDefinitionName == "签订前要点审批"){
		url = window.rootPath + '/ui/task/audit-nodes/beforecontract/'+ selects[0].entityId;
	}else if(selects[0].processDefinitionName == "投标"){
		url = window.rootPath + '/ui/task/audit-nodes/bid/'+ selects[0].entityId;
	}else if(selects[0].processDefinitionName == "外贸价格单"){
		url = window.rootPath + '/ui/task/audit-nodes/quote-foreign/'+ selects[0].entityId;
	}else if(selects[0].processDefinitionName == "普通价格单"){
		url = window.rootPath + '/ui/task/audit-nodes/quote/'+ selects[0].entityId;
	}else if(selects[0].processDefinitionName == "三包服务"){
		url = window.rootPath + '/ui/task/audit-nodes/afterSaleInHouse/'+ selects[0].entityId;
	}
	jQuery.get(encodeURI(url), null, function(html) {
		jQuery('#modal-audit-nodes-content').html(html);
		jQuery('#modal-audit-nodes').modal("show");
	});
});

//查看详情
jQuery('.detailBtn').on("click",function(){
	var selects = getSelect("#dataTable", 1);
	if (selects.length > 1) {
		$.springLemonDialog({
			content : "一次只能查看一条记录",// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				$(this).closeDialog(modal);
			}
		});
		return;
	}
	if (selects.length < 1) {
		$.springLemonDialog({
			content : "请选择要查看审批的记录",// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				$(this).closeDialog(modal);
			}
		});
		return;
	}
	var url;
	if(selects[0].processDefinitionName == "签订前要点审批"){
		url=window.rootPath+'/ui/beforecontract/check/'+ selects[0].entityId;
	}else if(selects[0].processDefinitionName == "投标"){
		 url = window.rootPath + '/ui/bid/bidsee/' +'?id='+ selects[0].entityId;
	}else if(selects[0].processDefinitionName == "外贸价格单"){
		url =  window.rootPath + "/ui/quote-foreign/detail?quoteForeignId=" + selects[0].entityId;
	}else if(selects[0].processDefinitionName == "普通价格单"){
		url = window.rootPath+"/ui/quote/see"+"?quoteId="+selects[0].entityId;
	}else if(selects[0].processDefinitionName == "三包服务"){
		var afterSaleType = "三包服务"
		url =window.rootPath + "/ui/afterSaleTicket/ticketDetail?ticketId=" + selects[0].entityId + "&afterSaleType="+ afterSaleType;
	}
	window.location = url;
});


//查看审批
jQuery('.submitBtn2').on("click",function(){
	var selects = getSelect("#tab", 1);
	if (selects.length > 1) {
		$.springLemonDialog({
			content : "一次只能查看一条记录",// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				$(this).closeDialog(modal);
			}
		});
		return;
	}
	if (selects.length < 1) {
		$.springLemonDialog({
			content : "请选择要查看审批的记录",// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				$(this).closeDialog(modal);
			}
		});
		return;
	}
	var url;
	if(selects[0].processDefinitionName == "签订前要点审批"){
		url = window.rootPath + '/ui/task/audit-nodes/beforecontract/'+ selects[0].entityId;
	}else if(selects[0].processDefinitionName == "投标"){
		url = window.rootPath + '/ui/task/audit-nodes/bid/'+ selects[0].entityId;
	}else if(selects[0].processDefinitionName == "外贸价格单"){
		url = window.rootPath + '/ui/task/audit-nodes/quote-foreign/'+ selects[0].entityId;
	}else if(selects[0].processDefinitionName == "普通价格单"){
		url = window.rootPath + '/ui/task/audit-nodes/quote/'+ selects[0].entityId;
	}else if(selects[0].processDefinitionName == "三包服务"){
		url = window.rootPath + '/ui/task/audit-nodes/afterSaleInHouse/'+ selects[0].entityId;
	}
	jQuery.get(encodeURI(url), null, function(html) {
		jQuery('#modal-audit-nodes-content').html(html);
		jQuery('#modal-audit-nodes').modal("show");
	});
});

//查看详情 
jQuery('.detailBtn2').on("click",function(){
	var selects = getSelect("#tab", 1);
	if (selects.length > 1) {
		$.springLemonDialog({
			content : "一次只能查看一条记录",// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				$(this).closeDialog(modal);
			}
		});
		return;
	}
	if (selects.length < 1) {
		$.springLemonDialog({
			content : "请选择要查看审批的记录",// 确认文本
			clickButton : function(sender, modal, index) {// 按钮事件处理
				$(this).closeDialog(modal);
			}
		});
		return;
	}
	var url;
	if(selects[0].processDefinitionName == "签订前要点审批"){
		url=window.rootPath+'/ui/beforecontract/check/'+ selects[0].entityId;
	}else if(selects[0].processDefinitionName == "投标"){
		 url = window.rootPath + '/ui/bid/bidsee/' +'?id='+ selects[0].entityId;
	}else if(selects[0].processDefinitionName == "外贸价格单"){
		url =  window.rootPath + "/ui/quote-foreign/detail?quoteForeignId=" + selects[0].entityId;
	}else if(selects[0].processDefinitionName == "普通价格单"){
		url = window.rootPath+"/ui/quote/see"+"?quoteId="+selects[0].entityId;
	}else if(selects[0].processDefinitionName == "三包服务"){
		var afterSaleType = "三包服务"
		url =window.rootPath + "/ui/afterSaleTicket/ticketDetail?ticketId=" + selects[0].entityId + "&afterSaleType="+ afterSaleType;
	}
	window.location = url;
});

jQuery(document).ready(function () {
		//我的审批
	   serverTable=  jQuery('#dataTable').DataTable({
        "serverSide": true,
        "ordering": false,
        "ajax": {
            "dataType": "json",
            "type": "get",
            "cache": false,
            "url": window.rootPath+'/ui/task/pcgetmyins',
            "data": function (d) {
                return $.extend({}, d, serverData);
            }
        },
        columns: [{
			        	data: null,
			            defaultContent: ""
			        },
			        {
			        	data:null,
					    render: function(data, type, full, meta){
					    	var operate ='<input type="checkbox" class="checkchild">';
					    	var id=data.id;
					    	return operate;
							}
		            },
                  	{
		                data: 'taskName'
		                
		            },
		            {
		                data: 'processDefinitionName'
		            },
		            {
		                data: 'starterName'
		            },
		            {
		            	data: 'createTime',
		            	render: function (data, type, full, meta) {
		                    if (data)
		                        return moment(data).format('YYYY/MM/DD');
		                    else
		                        return '';
		                }
		            }
		          ],
        "drawCallback": function ( oSettings ) {             
            var k = 0;
            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

            for ( var i=oSettings._iDisplayStart, iLen=total ; i<iLen ; i++ )
            {
                $('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[k] ].nTr ).text( i+1 );
                k++;
            }
                return;
        }
    });

	   //我发起的审批
	   serverTable=  jQuery('#tab').DataTable({
	        "serverSide": true,
	        "ordering": false,
	        "ajax": {
	            "dataType": "json",
	            "type": "get",
	            "cache": false,
	            "url": window.rootPath+'/ui/task/pcgetmystarts',
	            "data": function (d) {
	                return $.extend({}, d, serverData);
	            }
	        },
	        columns: [{
				        	data: null,
				            defaultContent: ""
				        },
				        {
				        	data:null,
						    render: function(data, type, full, meta){
						    	var operate ='<input type="checkbox" class="checkchild">';
						    	var id=data.id;
						    	return operate;
								}
			            },
	                  	{
			                data: 'taskName'
			                
			            },
			            {
			                data: 'processDefinitionName'
			            },
			            {
			                data: 'starterName'
			            },
			            {
			            	data: 'createTime',
			            	render: function (data, type, full, meta) {
			                    if (data)
			                        return moment(data).format('YYYY/MM/DD');
			                    else
			                        return '';
			                }
			            }
			          ],
	        "drawCallback": function ( oSettings ) {             
	            var k = 0;
	            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

	            for ( var i=oSettings._iDisplayStart, iLen=total ; i<iLen ; i++ )
	            {
	                $('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[k] ].nTr ).text( i+1 );
	                k++;
	            }
	                return;
	        }
	    });
	   
});